<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="125px">
      <el-form-item label="手机号码" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="fullName">
        <el-input
          v-model="queryParams.fullName"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="区域" prop="region">
        <el-input
          v-model="queryParams.region"
          placeholder="请输入区域"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="请选择性别" clearable size="small">
          <el-option
            v-for="dict in dict.type.user_sex"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="证件类型" prop="idcardType">
        <el-select v-model="queryParams.idcardType" placeholder="请选择证件类型" clearable size="small">
          <el-option
            v-for="dict in dict.type.idcard_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="证件号码" prop="idcardNumber">
        <el-input
          v-model="queryParams.idcardNumber"
          placeholder="请输入证件号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="经销商" prop="dealerName">
        <el-input
          v-model="queryParams.dealerName"
          placeholder="请输入经销商"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职位" prop="position">
        <el-input
          v-model="queryParams.position"
          placeholder="请输入职位"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="衣服尺码" prop="field1">
        <el-select v-model="queryParams.field1" placeholder="请选择" clearable size="small">
          <el-option
            v-for="dict in dict.type.yifuchima"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否入住" prop="checkIn">
        <el-select v-model="queryParams.checkIn" placeholder="请选择是否入住" clearable size="small">
          <el-option
            v-for="dict in dict.type.is_check_in"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="房间类型" prop="roomType">
        <el-select v-model="queryParams.roomType" placeholder="请选择房间类型" clearable size="small">
          <el-option
            v-for="dict in dict.type.room_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="拼房类型" prop="pfType">
        <el-select v-model="queryParams.pfType" placeholder="请选择拼房类型" clearable size="small">
          <el-option
            v-for="dict in dict.type.pf_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="拼房人姓名" prop="pfName">
        <el-input
          v-model="queryParams.pfName"
          placeholder="请输入拼房人姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="抵达方式" prop="arrivalMode">
        <el-select v-model="queryParams.arrivalMode" placeholder="请选择抵达方式" clearable size="small">
          <el-option
            v-for="dict in dict.type.arrival_mode"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="抵达航班号/车次" prop="arrivalNumber">
        <el-input
          v-model="queryParams.arrivalNumber"
          placeholder="请输入抵达航班号/车次"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="返程方式" prop="returnMode">
        <el-select v-model="queryParams.returnMode" placeholder="请选择返程方式" clearable size="small">
          <el-option
            v-for="dict in dict.type.arrival_mode"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="返回航班号/车次" prop="returnNumber">
        <el-input
          v-model="queryParams.returnNumber"
          placeholder="请输入返回航班号/车次"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择审核状态" clearable size="small">
          <el-option
            v-for="dict in dict.type.user_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['biz:userinfo:add']"
        >新增</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['biz:userinfo:edit']"
        >审核</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['biz:userinfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['biz:userinfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="userinfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="ID" align="center" prop="userid" /> -->
      <el-table-column label="手机号码" align="center" prop="phone" />
      <el-table-column label="姓名" align="center" prop="fullName" />
      <el-table-column label="区域" align="center" prop="region" />
      <el-table-column label="性别" align="center" prop="sex">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.user_sex" :value="scope.row.sex"/>
        </template>
      </el-table-column>
      <!-- <el-table-column label="证件类型" align="center" prop="idcardType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.idcard_type" :value="scope.row.idcardType"/>
        </template>
      </el-table-column>
      <el-table-column label="证件号码" align="center" prop="idcardNumber" /> -->
      <el-table-column label="经销商" align="center" prop="dealerName" />
      <el-table-column label="职位" align="center" prop="position" />
      <el-table-column label="衣服尺码" align="center" prop="field1" />
      <el-table-column label="是否入住" align="center" prop="checkIn">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.is_check_in" :value="scope.row.checkIn"/>
        </template>
      </el-table-column>
      <el-table-column label="房间类型" align="center" prop="roomType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.room_type" :value="scope.row.roomType"/>
        </template>
      </el-table-column>
      <el-table-column label="拼房类型" align="center" prop="pfType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.pf_type" :value="scope.row.pfType"/>
        </template>
      </el-table-column>
      <el-table-column label="拼房人姓名" align="center" prop="pfName" />
      <!-- <el-table-column label="抵达方式" align="center" prop="arrivalMode">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.arrival_mode" :value="scope.row.arrivalMode"/>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="抵达航班号/车次" align="center" prop="arrivalNumber" /> -->
      <!-- <el-table-column label="抵达时间" align="center" prop="arrivalTime" width="180">
      </el-table-column> -->
      <!-- <el-table-column label="返程方式" align="center" prop="returnMode">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.arrival_mode" :value="scope.row.returnMode"/>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="返回航班号/车次" align="center" prop="returnNumber" /> -->
      <!-- <el-table-column label="返程时间" align="center" prop="returnTime" width="180">
      </el-table-column> -->
      <el-table-column label="审核状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.user_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <!-- <template slot-scope="scope">
          <span>{{ parseTime(scope.row.returnTime, '{y}-{m}-{d}') }}</span>
        </template> -->
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['biz:userinfo:edit']"
          >审核</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['biz:userinfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或审核用户信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="70%" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="手机号码" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号码" />
        </el-form-item>
        <el-form-item label="姓名" prop="fullName">
          <el-input v-model="form.fullName" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="区域" prop="region">
          <el-input v-model="form.region" placeholder="请输入区域" />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择性别">
            <el-option
              v-for="dict in dict.type.user_sex"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="证件类型" prop="idcardType">
          <el-select v-model="form.idcardType" placeholder="请选择证件类型">
            <el-option
              v-for="dict in dict.type.idcard_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="证件号码" prop="idcardNumber">
          <el-input v-model="form.idcardNumber" placeholder="请输入证件号码" />
        </el-form-item> -->
        <el-form-item label="经销商" prop="dealerName">
          <el-input v-model="form.dealerName" placeholder="请输入经销商" />
        </el-form-item>
        <el-form-item label="职位" prop="position">
          <el-input v-model="form.position" placeholder="请输入职位" />
        </el-form-item>
        <el-form-item label="衣服尺码" prop="field1">
          <el-select v-model="form.field1" placeholder="请选择衣服尺码">
            <el-option
              v-for="dict in dict.type.yifuchima"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否入住" prop="checkIn">
          <el-select v-model="form.checkIn" placeholder="请选择是否入住">
            <el-option
              v-for="dict in dict.type.is_check_in"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="房间类型" prop="roomType">
          <el-select v-model="form.roomType" placeholder="请选择房间类型">
            <el-option
              v-for="dict in dict.type.room_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="拼房类型" prop="pfType">
          <el-select v-model="form.pfType" placeholder="请选择拼房类型">
            <el-option
              v-for="dict in dict.type.pf_type"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="拼房人姓名" prop="pfName">
          <el-input v-model="form.pfName" placeholder="请输入拼房人姓名" />
        </el-form-item>
        <el-form-item label="抵达方式" prop="arrivalMode">
          <el-select v-model="form.arrivalMode" placeholder="请选择抵达方式">
            <el-option
              v-for="dict in dict.type.arrival_mode"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="抵达航班号/车次" prop="arrivalNumber">
          <el-input v-model="form.arrivalNumber" placeholder="请输入抵达航班号/车次" />
        </el-form-item>
        <el-form-item label="抵达时间" prop="arrivalTime">
          <el-date-picker clearable size="small"
            v-model="form.arrivalTime"
            type="datetime"
            value-format="yyyy-MM-dd hh:mm:ss"
            placeholder="选择抵达时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="返程方式" prop="returnMode">
          <el-select v-model="form.returnMode" placeholder="请选择返程方式">
            <el-option
              v-for="dict in dict.type.arrival_mode"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="返回航班号/车次" prop="returnNumber">
          <el-input v-model="form.returnNumber" placeholder="请输入返回航班号/车次" />
        </el-form-item>
        <el-form-item label="返程时间" prop="returnTime">
          <el-date-picker clearable size="small"
            v-model="form.returnTime"
            type="datetime"
            value-format="yyyy-MM-dd hh:mm:ss"
            placeholder="选择返程时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="审核状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择审核状态">
            <el-option
              v-for="dict in dict.type.user_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核备注" prop="auditRemark">
          <el-input v-model="form.auditRemark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listUserinfo, getUserinfo, delUserinfo, addUserinfo, updateUserinfo, exportUserinfo } from "@/api/biz/userinfo";

export default {
  name: "Userinfo",
  dicts: ['user_sex', 'idcard_type', 'is_check_in', 'room_type', 'pf_type', 'arrival_mode', 'arrival_mode', 'user_status', 'yifuchima'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户信息表格数据
      userinfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        phone: null,
        fullName: null,
        region: null,
        sex: null,
        idcardType: null,
        idcardNumber: null,
        dealerCode: null,
        dealerName: null,
        position: null,
        checkIn: null,
        roomType: null,
        pfType: null,
        pfName: null,
        arrivalMode: null,
        arrivalNumber: null,
        arrivalTime: null,
        returnMode: null,
        returnNumber: null,
        returnTime: null,
        auditRemark: null,
        status: null,
        field1: null,
        field2: null,
        field3: null,
        field4: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        phone: [
          { required: true, message: "手机号码不能为空", trigger: "blur" }
        ],
        fullName: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        region: [
          { required: true, message: "区域不能为空", trigger: "blur" }
        ],
        sex: [
          { required: true, message: "性别不能为空", trigger: "change" }
        ],
        idcardType: [
          { required: true, message: "证件类型不能为空", trigger: "change" }
        ],
        idcardNumber: [
          { required: true, message: "证件号码不能为空", trigger: "blur" }
        ],
        dealerName: [
          { required: true, message: "经销商不能为空", trigger: "blur" }
        ],
        position: [
          { required: true, message: "职位不能为空", trigger: "blur" }
        ],
        checkIn: [
          { required: true, message: "是否入住不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户信息列表 */
    getList() {
      this.loading = true;
      listUserinfo(this.queryParams).then(response => {
        this.userinfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        userid: null,
        phone: null,
        fullName: null,
        region: null,
        sex: null,
        idcardType: null,
        idcardNumber: null,
        dealerCode: null,
        dealerName: null,
        position: null,
        checkIn: null,
        roomType: null,
        pfType: null,
        pfName: null,
        arrivalMode: null,
        arrivalNumber: null,
        arrivalTime: null,
        returnMode: null,
        returnNumber: null,
        returnTime: null,
        auditRemark: null,
        status: null,
        field1: null,
        field2: null,
        field3: null,
        field4: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.userid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户信息";
    },
    /** 审核按钮操作 */
    handleUpdate(row) {
      this.reset();
      const userid = row.userid || this.ids
      getUserinfo(userid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "审核用户信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.userid != null) {
            updateUserinfo(this.form).then(response => {
              this.$modal.msgSuccess("审核成功");
              this.open = false;
              this.getList();
            });
          } else {
            addUserinfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const userids = row.userid || this.ids;
      this.$modal.confirm('是否确认删除用户信息编号为"' + userids + '"的数据项？').then(function() {
        return delUserinfo(userids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有用户信息数据项？').then(() => {
        this.exportLoading = true;
        return exportUserinfo(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
};
</script>
